package com.mineapp.weight

import android.content.Context
import android.graphics.Color
import android.support.v7.widget.Toolbar
import android.text.TextUtils
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.common.R

/**
 * Created by mac on 2017/8/1.
 */
class ToolbarView(context: Context) : FrameLayout(context) {
    var mTitleView: TextView? = null
    var mToolbar: Toolbar? = null

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.toolbar_layout, this)
        mToolbar = view.findViewById(R.id.toolbar)
        val layoutParams: FrameLayout.LayoutParams = FrameLayout.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,180)
        layoutParams.gravity = Gravity.CENTER
        mToolbar?.layoutParams = layoutParams
    }

    fun setTitle(title: String?) {
        if(TextUtils.isEmpty(title)) return
        mTitleView = TextView(context)
        val txtLayoutParams = Toolbar.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.MATCH_PARENT)
        txtLayoutParams.gravity = Gravity.CENTER
        mTitleView?.gravity = Gravity.CENTER
        mTitleView?.layoutParams = txtLayoutParams
        mTitleView?.setTextColor(Color.WHITE)
        mTitleView?.textSize = 25f
        mTitleView?.maxLines = 1
        mTitleView?.text = title
        mToolbar?.addView(mTitleView)
    }
}